<template>
  <div class="nav-header">
    <el-icon @click="foldClick">
      <template v-if="!isFold">
        <Fold />
      </template>
      <template v-else>
        <Expand />
      </template>
    </el-icon>
    <div class="content">
      <lzbreadcrumb :breadcrumbData="breadcrumbData" />
      <user-info />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import { Fold, Expand } from '@element-plus/icons-vue'

import UserInfo from './user-info.vue'
import Lzbreadcrumb from '@/base-ui/breadcrumb'

import { mapPathToBreadCrumb } from '@/utils/map-menus'
import { useStore } from '@/store'
import { useRoute } from 'vue-router'

export default defineComponent({
  emits: ['foldChange'],
  components: {
    Fold,
    Expand,
    UserInfo,
    Lzbreadcrumb
  },
  setup(props, { emit }) {
    const isFold = ref(false)

    const store = useStore()
    const route = useRoute()

    const breadcrumbData = computed(() => {
      const useMenus = store.state.login.userMenus
      const currentPath = route.path
      return mapPathToBreadCrumb(useMenus, currentPath)
    })

    const foldClick = () => {
      isFold.value = !isFold.value
      emit('foldChange', isFold.value)
    }

    return {
      isFold,
      breadcrumbData,
      foldClick
    }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  align-items: center;
  width: 100%;
  .el-icon {
    font-size: 30px;
    cursor: pointer;
  }

  .content {
    display: flex;
    flex: 1;
    padding-left: 20px;
    justify-content: space-between;
  }
}
</style>
